﻿using System;
using Sundstrom.Mvvm.Validation;

namespace Sundstrom.Mvvm.Tests.ViewModels
{
    public class ValidatedViewModel : ExtendedViewModelBase
    {
        private string _name;
        private int _age;

        [NotEmpty]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                ValidateProperty(() => Name);
            }
        }

        public int Age
        {
            get { return _age; }
            set
            {
                _age = value;
                ValidateProperty(() => Age);
            }
        }

        public void ValidateAge()
        {
            if(_age < 18)
                AddError(() => Age, "Must have an age of 18.");
        }
    }
}
